package com.blog.module.photos.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.blog.common.mybatis.Page;
import com.blog.common.mybatis.ParsePagination;
import com.blog.module.photos.mapper.PhotosInfoMapper;
import com.blog.module.photos.pojo.Photos;
import com.blog.module.photos.pojo.PhotosExample;
import com.blog.module.photos.pojo.PhotosInfo;
import com.blog.module.photos.pojo.PhotosInfoExample;
import com.blog.module.photos.pojo.PhotosInfoExample.Criteria;


@Service
public class PhotosInfoService {

	
	@Autowired
	private PhotosInfoMapper photosInfoMapper;
	
	
	public Page selectPhotosInfoByPhotosId(PhotosInfo photosInfo ){
		ParsePagination pagination = new ParsePagination();
		int pageNo = pagination.getPageNo();
		int pageSize = pagination.getPageSize();
		PhotosInfoExample example = new PhotosInfoExample();
		Criteria criteria=  example.createCriteria();
		if (photosInfo != null) {
			criteria.andTitleEqualTo(photosInfo.getTitle());
			criteria.andPhotosIdEqualTo(photosInfo.getPhotosId());
		}
		int count = photosInfoMapper.countByExample(example);
		List<PhotosInfo> list = new ArrayList<PhotosInfo>();
		Page page = new Page(count, pageNo, pageSize, list);
		example.setLimitStart((pageNo - 1) * pageSize);
		example.setLimitEnd(pageSize);
		list = photosInfoMapper.selectByExample(example);
		page.setList(list);
		return page;
	}
	
	public PhotosInfo selectById(int id){
		return photosInfoMapper.selectByPrimaryKey(id);
	}
	
	public int insert(PhotosInfo photosInfo ){
		  return photosInfoMapper.insert(photosInfo);
	}
	
	
	public int update(PhotosInfo photosInfo){
		return photosInfoMapper.updateByPrimaryKeySelective(photosInfo);
	}
	public int del(int id){
		return photosInfoMapper.deleteByPrimaryKey(id);
	}
	
}
